<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>数据库备份</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="Author" content="larry" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="/static/admin/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/common/css/animate.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="larry-container larryms-admin">
        <div class="layui-row layui-col-space20">
            <div class="layui-col-xs12 animated fadeInRightBig">
                <section class="larry-panel">
                    <div class="larryms-page-header">
                        <span class="tit">数据库备份</span>
                    </div>
                    <div class="larryms-page-body">
                        <p>
                            <button class="layui-btn layui-btn-normal layui-btn-sm" style="background-color: #1ab394" id="backup">立即备份</button>
                            <button class="layui-btn layui-btn-warm layui-btn-sm" style="background-color: #23c6c8" id="optimize">优化表</button>
                            <button class="layui-btn layui-btn-danger layui-btn-sm" id="repair">修复表</button>
                        </p>
                        <form name="backup" method="post">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>数据量</th>
                                        <th>数据大小</th>
                                        <th>数据库类型</th>
                                        <th>创建时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                                {notempty name="data"}
                                    {volist name="data" id="vo"}
                                        <tr>
                                            <td>{$vo.name}</td>
                                            <td>【{$vo.rows}】 条记录</td>
                                            <td>{$vo.data_length|format_bytes}</td>
                                            <td>{$vo.engine}</td>
                                            <td>{$vo.create_time}</td>
                                            <input type="hidden" name="id[]" value="{$vo.name}" id="id">
                                        </tr>
                                    {/volist}
                                {else /}
                                    <td colspan="7" style="text-align: center"> 暂未发现数据库表! </td>
                                {/notempty}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
<!-- 加载js文件-->
<script type="text/javascript" src="/static/admin/common/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery', 'layer'], function(){
        var $ = layui.$ //重点处
            ,layer = layui.layer;
        //备份数据库
        $('#backup').click(function(){
            //var id = $('#id').val();
            var inputObj = $("input[name='id[]']");
            //console.log(inputObj);
            var data= new Array;
            inputObj.each(function(){
                if($(this).val()) data.push($(this).val());
            })
            $.ajax({
                type:"POST",
                url:"{:url('admin/data/backup')}",
                dataType:"JSON",
                data:{'id':data},
                success:function(data){
                    if(data.code == '1'){
                        layer.msg(data.msg, {icon: 6});
                    }else if(data.code == '-1'){
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });
            return false;
        })
        //优化数据库
        $('#optimize').click(function(){
            //var id = $('#id').val();
            var inputObj = $("input[name='id[]']");
            console.log(inputObj);
            var data= new Array;
            inputObj.each(function(){
                if($(this).val()) data.push($(this).val());
            })
            $.ajax({
                type:"POST",
                url:"{:url('admin/data/optimize')}",
                dataType:"JSON",
                data:{'id':data},
                success:function(data){
                    if(data.code == '1'){
                        layer.msg(data.msg, {icon: 6});
                    }else if(data.code == '-1'){
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });
            return false;
        })
        //修复数据库
        $('#repair').click(function(){
            //var id = $('#id').val();
            var inputObj = $("input[name='id[]']");
            console.log(inputObj);
            var data= new Array;
            inputObj.each(function(){
                if($(this).val()) data.push($(this).val());
            })
            $.ajax({
                type:"POST",
                url:"{:url('admin/data/repair')}",
                dataType:"JSON",
                data:{'id':data},
                success:function(data){
                    if(data.code == '1'){
                        layer.msg(data.msg, {icon: 6});
                    }else if(data.code == '-1'){
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });
            return false;
        })
    });
</script>
</body>
</html>